//
//  MainSubLiteratureViewModel.m
//  EnvironmentalProtection
//
//  Created by HCreater on 2018/10/23.
//  Copyright © 2018年 HCreater. All rights reserved.
//

#import "MainSubLiteratureViewModel.h"

#import "StwxTableViewModel.h"

@implementation MainSubLiteratureViewModel

- (void)initialize
{
    [super initialize];
    
    @weakify(self);
    
    DataManager* dm = [DataManager sharedDataManager];
    self.provinceListData = dm.locationPLData;
    
    StwxTableViewModel* tvm = [[StwxTableViewModel alloc] initWithParams:@{}];
    tvm.perPage = List_PageSize;
    tvm.lastPage = 1000;
    tvm.cellHeight = 120;
    /// 允许下拉刷新
    tvm.shouldPullDownToRefresh = YES;
    /// 允许上拉加载
    tvm.shouldPullUpToLoadMore = YES;
    tvm.tag = 10;
    self.stwxTVM = tvm;
    
    // 通知
    [[[NSNotificationCenter defaultCenter] rac_addObserverForName:Notify_FirstPageReload object:nil] subscribeNext:^(id x)
     {
         @strongify(self);
         
         NSNotification* notification = x;
         
         self.provinceListData = notification.object;
     }];
    
    // 地区
    [[RACObserve(self, provinceListData) takeUntil:[self rac_willDeallocSignal]] subscribeNext:^(id x)
     {
         @strongify(self);
         
         self.stwxTVM.areaID = self.provinceListData ? self.provinceListData.areaID : @"0";
         
         [self.stwxTVM.requestDataCmd execute:@{@"LoadIndex":@0}];
     }];
}

@end
